
<div class="restpwd">
    <form class="niceform" id="myform" action="" method="post">
            <div  class="restpwd-title">重置登录密码</div>
            <div class="restpwd-con">
                <p>请输入您注册的邮箱地址，系统将发送重置密码的链接到邮箱中</p>
                <div class="input-group">
                    <label for="email" class="input-group-addon">邮箱账号</label>
                    <input type="text" name="email" id="email" class="form-control" maxlength="30" required="required" placeholder="请填写你的邮箱"/>
                </div>
                <div class="input-group">
                     <label for="verifycode" class="input-group-addon">验证码</label>
                     <input type="text" name="verifycode" id="verifycode" class="form-control" maxlength="30" required="required" placeholder="请填写验证码"/>
                     <div class="register-captcha-img"><?php if (isset($captcha) && isset($captcha['image'])) echo $captcha['image']; ?></div>
                </div>
                <input type="submit" class="btn btn-success form-control" id="sendmailbtn" value="发送重置密码邮件">
        </div>
    </form>
</div>
<script type="text/javascript">
    $(function () {
        $.AutoComplete('#email');
        $('#myform').validate({
            submitHandler: function (form) {
                $.ajax({
                    url:"<?php echo base_url('api/setPwd_Token') ?>",
                    type:"post",
                    data:$('#myform').serialize(),
                    dataType:"json",
                    beforeSend:function(){
                        showProgressNoty();
                    },
                    complete: function () {
                        closeProgressNoty();
                    },
                    success:function(rsp){
                        try {
                            noty({type: rsp.type, text: rsp.message, callback: {
                                afterClose: function () {
                                    switch (rsp.type) {
                                        case 'success':
                                            noty({
                                                type:'warning',
                                                text:'邮件已发送至您邮箱，现在去重置吗？',
                                                buttons: [
                                                    {
                                                        addClass: 'btn btn-sm btn-danger', text: '确定',
                                                        onClick: function ($noty) {
                                                            $noty.close();
                                                            window.location.href=rsp.data;
                                                        }
                                                    },
                                                    {
                                                        addClass: 'btn btn-sm btn-default', text: '取消',
                                                        onClick: function ($noty) {
                                                            $noty.close();
                                                        }
                                                    }
                                                ]
                                            });
                                            break;
                                        case 'error':
                                            noty({type:rsp.type,text:rsp.message});
                                            break;
                                        default:
                                            break;
                                    }
                                }
                            }});
                        } catch (ex) {
                            noty({type: 'error', text: '发生内部错误，请联系管理员'});
                            throw ex;
                        }
                    }
                });
            }
        });

        $('.register-captcha-img').click(function () {
            $.getJSON('<?php echo base_url('api/getCaptcha');?>', function (rsp) {
                try {
                    switch (rsp.type) {
                        case 'success':
                            $('.register-captcha-img').html(rsp.data);
                            break;
                        default :
                            noty({type: rsp.type, text: rsp.message});
                            break;
                    }
                } catch (ex) {
                    noty({type: 'error', text: '发生内部错误，请联系管理员'});
                    throw ex;
                }
            });
        });
    });
</script>